/*
 * storage_manager.h
 *
 *  Created on: Mar 11, 2014
 *      Author: lifeng
 */

#ifndef STORAGE_MANAGER_H_
#define STORAGE_MANAGER_H_

#include <stdio.h>
#include <pthread.h>

#include "record_dic.h"

#include "../lib/block_manager.h"

#include "../lib/block_filter.h"

#define SERIAL_BUFFER_SIZE	(4*1024)

struct record_manager {
	struct block_manager manager;
	struct record_dic dics[2];
	int date_tbl[4][128];
	pthread_t thread_store;
	FILE * file;

	char serial_buffer[SERIAL_BUFFER_SIZE];
	int serial_length;
	pthread_mutex_t mutex_FileOpt;

};

struct record_manager* get_record_manager();
void request_playback(struct record_manager*manager, int play_index,
		struct block*wav_block);
void request_data(struct record_manager*manager, int section, char *data,
		int length);
void store_serial_data(struct record_manager * manager, char *data, int length);
void store_wave_data(struct record_manager * manager, struct block *pblock);
void flush_all_data(struct record_manager * manager);
void set_disk_using(int val);
int get_disk_using();
void store_dictionary(struct record_manager *manager);

/*
 *调用本函数时应该是系统断电不再有其他比当前任务更加重要的任务,
 *不再通过消息传递事件
 * */
void flushAllData();

#endif /* STORAGE_MANAGER_H_ */
